randomation_vehicle_physicsfandomcom-20200214-history
VehicleParent
__FORCETOC__This is the main script for controlling vehicles. It should be attached to the uppermost object in a vehicle's hierarchy; the same object with the vehicle's rigidbody component. For info on input axes, read the Input Axes section of ControlScript. Variables AI - Determines whether the vehicle is controlled by user input. If this is set to true, then the vehicle will ignore user input. This physics package does not come with an AI controller, but you can modify this script to add in your own AI code. This should be done within FixedUpdate to keep behavior independent of framerate. Ignition - Is the vehicle turned on? Steer and brake input will still be accounted for if this is false, as well as flip input if maxFlipSpeed is greater than 0. Wheels - Contains the wheel collider transforms of the wheels. With a bike, the front wheel must be first in the list. Sus Center Of Mass - Should the center of mass of the rigidbody automatically be lowered when the vehicle is grounded? The center of mass is lowered based on the average suspension length of the wheels. This reduces the chance of the vehicle tipping over. Start Center Of Mass - The center of mass of the rigidbody. If susCenterOfMass is true, this is what the center of mass will be while the vehicle is in the air. Otherwise this will always be the center of mass of the rigidbody. Center Of Mass Offset - Extra distance to lower the center of mass when the vehicle is grounded, but only if susCenterOfMass is true. Negative values will raise the center of mass. Max Drive - Engine power, directly affects top speed and acceleration. Default is 60. Force Max Speed - If left at zero, the top speed will be calculated based on maxDrive, maxGears, and gearLength. If a number greater than zero is entered, the top speed will be replaced with this. This represents meters per second. Max Steer - Maximum steering angle. Default is 30. Steer Speed - Multiplier for the steering speed. Crab Steer - Should this vehicle use crab steering? This is when all wheels steer the same direction, allowing the vehicle to move diagonally or sideways depending on maxSteer. This can be toggled at run time. If it is true, all non-steering wheels will be temporarily allowed to steer. This is disabled on bikes and monowheels. For best results, use this on a vehicle with all-wheel drive. Max Gears - The number of forward gears in the transmission, there is always 1 reverse gear. Default is 6. Auto Shift - Should the vehicle use an automatic transmission? If set to false, holding the brake at a stop will not automatically shift the vehicle into reverse. Instead, the player must manually downshift into reverse and accelerate. Shift Delay - How many steps it takes to perform a gear shift. Default is 20. Gear Length - The length multiplier of the gears, creating a tradeoff between acceleration and top speed. Lowering it increases acceleration and decreases top speed, Raising lowers acceleration and increases top speed. Making this value too high may cause the vehicle to have insufficient torque to reach top speed. Default is 1. Brake - Multiplier for the brake strength of all wheels. Max Flip Speed - How fast the vehicle can be manually spun around by the player. An example of this would be having a bike which the player can flip with while in the air. Stop Flip - Should the vehicle automatically stop flipping if it happens to level out in the air? Dive Factor - The rate at which the vehicle should dive forward while in the air. If this is greater than 0, stop flip will be ignored. Down Force Factor - Multiplier for the downforce of the vehicle, it is the same for both forward and reverse driving. Flip Over Factor - Multiplier for how much the vehicle should try to roll over if it is on its side. Avoid Roll Over - Should the vehicle avoid tipping over if its wheels lift off the ground? If bike or monowheel, should it try to stand up? Kickstand - Will make bikes and monowheels tilt slightly to the left as if being held up by a kickstand. Can Crash - Is the vehicle capable of crashing? Can Boost - Is the vehicle capable of boosting? Boost - How much boost does the vehicle have to start with? (1 = full) Boost Type - Type of boost for the vehicle, valid values range from 0 to 4. 0: Normal boost, can boost whenever as long as the boost is greater than zero. 1: Chain boost, can only boost when the boost is full, and can chain multiple boosts together by jumping and drifting. 2: Power boost, can only boost when the boost is full, but all of the boost is used in one go and is more powerful than normal boost. The top speed is also increased more while boosting. 3: Drift boost, can only be used while drifting and when the boost is full. You can chain boosts together by drifting and boosting again. This comparable to what you might see in a kart racer. 4: Rocket boost, just like power boost, but adds forward motion to the vehicle while it is in the air and cannot be filled while being used. Boost Burn Rate - Multiplier for how fast the boost used used up. Boost Fill Rate - Multiplier for how fast the boost is filled. Boost Power - The power of the boost. Default is 0.3. Gravity Factor - Makes the vehicle fall faster in order to feel heavier. Default is 4. Density - The density of the vehicle which determines how quickly it sinks in water. Must be between 0 and 1.5, but will gradually increase to 2 if the vehicle is in water. If it is greater than 1.5 the vehicle is considered sunk, in which case if canSink is set to true, ignition will be set to false until the vehicle is out of water, where the density will gradually decrease to its original value. Default is 1. Can Sink - Can the vehicle sink in water? Sink Speed - How fast does the vehicle sink? This is a multiplier. Engine - The main engine audio source. Engine Idle - The engine idle audio source. Engine Open - The open engine audio source. EngineIdleOpen - The open engine idle audio source. If any of the engine audio sources are set to null, the pitch calculations and boost sounds will be disabled. For more info on engine sounds, read the Engine Sounds section of Setting Up a Vehicle. Boost Snd - The audio source for the looping boost sound which plays while the vehicle is boosting. Boost Start Source - The audio source for the sound which plays when the boost button is pressed or released. If either boostSnd or boostStartSource is null, canBoost will be set to false. Boost Start Snd - The audio clip for boost starting. Boost End Snd - The audio clip for boost ending. Reverse Snd - The sound of the reverse gear whine. Can be null. Hit Source - The collision audio source, will not play from collisions with undertray colliders. Can be null. Hits - Audio clips for the hitSource. Sparks - The particle system for collisions. Can be null. Spin Whoosh - Audio source which plays a whoosh sound while the vehicle spins in the air. Can be null. Min Pitch - The minimum pitch of the engine audio sources. Default is 0.5. Max Pitch - The maximum pitch of the engine audio sources. Default is 1.5. Engine Direction - The local space direction of the open engine sounds. This is basically the direction the grille faces on the vehicle. Forward is (0,0,1) and backwards is (0,0,-1). This is indicated with a red line gizmo in the editor. Bilateral Engine Sound - If this is true, the open engine sounds will play from both the engine direction and the negative engine direction. This is could be used for when you want the open engine sounds to be louder from both sides of the vehicle. Boost Flame Scale Factor - Multiplier for scaling the size of the boost flames. Default is 0.65. Boost Flames - Particle systems representing the boost flames. Undertray Colliders - Colliders on the underside of the vehicle. Friction Colliders - All other colliders on the vehicle, excluding those related to the wheels. For more info on colliders, read the Colliders section of Setting Up a Vehicle. Shadow - The projector of the vehicle's shadow. This can be null and if so, any calculations related to the shadow will be disabled. Cam Forward - The local space position of the camera looking forward, when the camera is on the hood (bonnet) of the vehicle. Cam Back - The local space position of the camera looking backwards, when the camera is on the rear of the vehicle. Cam forward and cam back are indicated with magenta frustrum gizmos in the editor. Cam Zoom - Extra distance the camera will sit away from the vehicle. Cam Angle Change - Extra angle by which the camera is raised above the vehicle. For more info on the camera, read CameraScript. Axis Assist - Should the steerInput and verticalInput axes be more sensitive when using a gamepad? This makes it easier to steer and pull a wheelie at the same time with a bike. Debug Teleport - Enable teleporting to the start position on the press of a button? This is true by default. Reset Rotation - Enable resetting the rotation on the press of a button? This is true by default. Hidden Variables These are variables which are not visible in the inspector, yet useful for writing scripts. delta - Delta time multiplier for events in Update(). fixedDelta - Multiplier for events in FixedUpdate(). allGrounded - Are all of the wheels grounded? allDrivenGrounded - Are all of the driven wheels grounded? oneGrounded - Is at least one wheel grounded? oneDrivenGrounded - Is at least one driven wheel grounded? onlyOneGrounded - Is only one wheel grounded? oneEBrakeGrounded - Is at least one ebrake wheel grounded? steerGrounded - Is at least one steered wheel grounded? allWheelsPopped - Are all of the tires popped? steer - The current steer angle of steered wheels. gear - The current gear the vehicle is in. -1 = reverse, 0 = neutral. Neutral is automatically skipped while shifting'.' forwardSpeed - Forward speed of the vehicle. sideSpeed - Sideways speed of the vehicle. upSpeed - Vertical speed of the vehicle. ForwardSpeed, sideSpeed, and upSpeed are in local space. For example, upSpeed is not equal to rigidbody.velocity.y. spawnTime - Number of physics steps the vehicle has been active. hasEngine - Does this vehicle have an engine? This is automatically set to false if one of the engine audio sources is set to null. Boost sounds are disabled if this is false. tempBoost - The secondary boost, used with boost types 1 and 3. This must be filled in order to create a boost chain. boostChain - The current boost chain accrued, only valid for boost types 1 and 3. boosting - Is the vehicle boosting? score - The current score accumulated. Out of the box, this package only uses it for earning boost. tempScore - The score of the current stunt. If the vehicle crashes, this is set to zero. If the vehicle lands correctly, this is added to the score variable. inWater - Is the vehicle submerged in water? volumeFactor - Multiplier for the volume of audio sources on the vehicle. This is altered by CameraScript at run time. normalAverage - The average normal of the surfaces the vehicle's wheels are sitting on. norm - A secondary object used to orient the vehicle and camera. The transform.up of this object is equal to normalAverage. It does not tilt to the side nor backwards/forwards during wheelies and turns with bikes and monowheels. If the vehicle is in the air, norm.rotation is equal to the rotation of the vehicle. Scroll down to the section labeled Norm Object for more info. t'argetLean' - The desired lean direction for bikes and monowheels. crashing - Is the vehicle crashing? accelConstant - Acceleration input, ranges from -1 to 1. brakeInput - Brake input, ranges from -1 to 1. camFollow - The main camera. velMag - The magnitude of rigidbody.velocity. angVelMag - The magnitude of rigidbody.angularVelocity. normalDot - The dot product of normalAverage and Vector3.up. forwardDot - The dot product of transform.forward and Vector3.up. upDot - The dot product of transform.up and Vector3.up. rightDot - The dot product of transform.right and Vector3.up. angVel - Shorthand for rigidbody.angularVelocity. drifting - Is the vehicle drifting? driftingActual - Same as drifting, but with a small delay to avoid counting micro drifts which only last for a fraction of a second. driftTimer - Duration of the current drift in steps, not in seconds. driftDist - Distance of the current drift in meters. airTimer - Air time in seconds. airDistance - Lateral distance traveled in air. airHeight - Height reached in air. If the vehicle has only fallen while in the air, this will remain at zero. groundedCenterOfMass - Calculated center of mass when susCenterOfMass is set to true. maxSpeed - The top speed of the vehicle. wheelTorque - Torque being delivered to the wheels. colliding - Is the vehicle colliding with something? susMax - Maximum suspension distance of the wheels. averageSusDistance - Average suspension distance of the wheels. averageWheelRadius - Average radius of the wheels. Functions ToggleIgnition - Toggles the ignition. RecalculateDriveFactor - Recalculates the multiplier for power distribution among the wheels. Call this if the driven variable of CarWheelColScript is changed at run time. SetDoppler - Set the doppler level for all audio sources on the vehicle. Norm Object Category:Scripts